package com.gxa.controller.set;

import com.gxa.common.R;
import com.gxa.entity.DistrictSysRole;
import com.gxa.service.RoleService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/role")
@Api(value = "角色管理的所有操作测试",tags = "角色管理接口API")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 分页查询所有角色
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryAllRolesByPage",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有角色接口",notes = "查询所有角色进行分页显示",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",required = true,dataType = "int",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryAllRolesByPage(int currentPage,int pageSize){
        return roleService.queryAllRolesByPage(currentPage,pageSize);
    }

    /**
     * 添加角色
     * @param districtSysRole
     * @return
     */
    @RequestMapping(value = "/addRole",method = RequestMethod.POST)
    @ApiOperation(value = "添加角色接口",notes = "添加角色信息",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误"),
            @ApiResponse(code=1001,message="添加失败，要添加的角色已存在！")
    })
    @ResponseBody
    public R addRole(@RequestBody @ApiParam(name = "districtSysRole",value = "角色信息",required = true) DistrictSysRole districtSysRole){
        return roleService.addRole(districtSysRole);
    }

    /**
     *
     * @param districtSysRole
     * @return
     */
    @RequestMapping(value = "/editRole",method = RequestMethod.POST)
    @ApiOperation(value = "编辑角色接口",notes = "编辑角色信息",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R editRole(@RequestBody @ApiParam(name = "districtSysRole",value = "角色信息",required = true) DistrictSysRole districtSysRole){
        return roleService.editRole(districtSysRole);
    }

    /**
     * 根据角色编号删除角色
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteRole",method = RequestMethod.POST)
    @ApiOperation(value = "删除角色接口",notes = "根据角色编号删除角色信息",httpMethod = "POST",response = R.class)
    @ApiImplicitParam(name = "id",value = "要删除的角色编号",required = true,dataType = "int",paramType = "query")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R deleteRole(int id){
        return roleService.deleteRole(id);
    }

    /**
     * 根据角色编号查询角色信息
     * @param id
     * @return
     */
    @RequestMapping(value = "/roleDetail",method = RequestMethod.GET)
    @ApiOperation(value = "查看角色详情接口",notes = "查看角色详情信息",httpMethod = "GET",response = R.class)
    @ApiImplicitParam(name = "id",value = "要查看详情的角色的编号",required = true,dataType = "int",paramType = "query")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R roleDetail(int id){
        return roleService.queryRoleDetail(id);
    }


    /**
     * 查询所有的角色信息
     * @return
     */
    @RequestMapping(value = "/queryAllRoles",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有角色接口",notes = "查询所有角色进行显示",httpMethod = "GET",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryAllRoles(){
        return roleService.queryAllRoles();
    }
}
